<?php

/**
 * This is the model class for table "question".
 *
 * The followings are the available columns in table 'question':
 * @property integer $ques_id
 * @property string $ques_title
 * @property string $ques_use_name
 * @property string $ques_use_email
 * @property string $ques_content
 * @property integer $ques_prv_id
 * @property integer $ques_date_create
 * @property integer $ques_view
 * @property integer $ques_active
 *
 * The followings are the available model relations:
 * @property Province $quesPrv
 */
class Question extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'question';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ques_title, ques_use_name, ques_use_email','required'),
         array('ques_prv_id, ques_date_create, ques_view, ques_active', 'numerical', 'integerOnly'=>true),
			array('ques_title, ques_use_name, ques_use_email', 'length', 'max'=>255),
			array('ques_content', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('ques_id, ques_title, ques_use_name, ques_use_email, ques_content, ques_prv_id, ques_date_create, ques_active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'quesPrv' => array(self::BELONGS_TO, 'Province', 'ques_prv_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ques_id' => 'ID',
			'ques_title' => 'Tiêu đề câu hỏi',
			'ques_use_name' => 'Tên người gửi',
			'ques_use_email' => 'Email',
			'ques_content' => 'Nội dung',
			'ques_prv_id' => 'Tỉnh/TP',
			'ques_date_create' => 'Ngày tạo',
         'ques_view' => 'Lượt xem',
			'ques_active' => 'Hiển thị',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ques_id',$this->ques_id);
		$criteria->compare('ques_title',$this->ques_title,true);
		$criteria->compare('ques_use_name',$this->ques_use_name,true);
		$criteria->compare('ques_use_email',$this->ques_use_email,true);
		$criteria->compare('ques_content',$this->ques_content,true);
		$criteria->compare('ques_prv_id',$this->ques_prv_id);
		$criteria->compare('ques_date_create',$this->ques_date_create);
		$criteria->compare('ques_active',$this->ques_active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Question the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
